import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

/*
 * Created by JFormDesigner on Tue Mar 15 20:14:56 CDT 2011
 */

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.*;
import javax.swing.*;
import java.util.*;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.concurrent.*;

import javax.swing.border.*;
import javax.swing.event.*;

public class GUI1 extends JFrame
{
	File downloadDirectory;
	int port;
	//public static HashMap<Peer, Connection> peers; // aka peers
	//public static HashMap<Peer, ArrayList<FileDetails>> peerToFileMap;
	//public static HashMap<FileDetails, ArrayList<Peer>> fileToPeerMap;
	public static ProjectManager myProject;
	File theDirectory;
	ExecutorService executor;
	boolean sr = false;

	//public HashSet<Peer> allPeers;
	//public Set<FileDetails> allFiles;

	public FileDetails lastSelectedFile;
	public Peer lastSelectedPeer;

	public GUI1()
	{
		initComponents();
		myProject = new ProjectManager(8888);
		port = myProject.getCurrentPort();
		lastSelectedFile = null;
		lastSelectedPeer = null;
	}

	private void fastestButtonActionPerformed(ActionEvent e)
	{

	}

	void loadFilesList()
	{

	}

	private void downloadButtonActionPerformed(ActionEvent e)
	{
		//		myProject.
		System.out.println(lstFiles.getSelectedValue());
		if (lstUsers.getSelectedIndex() != -1 && lstFiles.getSelectedIndex() != -1) {
			Peer selectedUser = (Peer) lstUsers.getSelectedValue();
			FileDetails selectedFile = (FileDetails) lstFiles.getSelectedValue();
			try {
				myProject.activeConnections.get(selectedUser).getFile(selectedFile.toString(), Integer.parseInt(selectedFile.getSize()));
			} catch (NumberFormatException e1) {} catch (IOException e1) {} catch (ClassNotFoundException e1) {}
		}
	}

	private void settingsMenuActionPerformed(ActionEvent e)
	{
		settingsDialog.setVisible(true);
	}

	private void okButtonActionPerformed(ActionEvent e)
	{
		settingsDialog.setVisible(false);
	}

	private void connectButtonActionPerformed(ActionEvent e)
	{
		Peer p = new Peer(myProject.ipfilter(connectField.getText()));
		myProject.connectTo(p, port);
	}

	private void lastModifiedButtonActionPerformed(ActionEvent e)
	{

	}

	private void menuItem2ActionPerformed(ActionEvent e)
	{

	}

	private void ExitActionPerformed(ActionEvent e) throws InterruptedException
	{
		myProject.shutdown();
		Thread.sleep(1000);
		System.exit(1);
	}

	private void refreshButtonActionPerformed(ActionEvent e)
	{
		System.out.println("haha");
		myProject.refresh();

		DefaultListModel newlstUsersModel = new DefaultListModel();
		for (Peer p : GUI1.myProject.peerToFileMap.keySet()) {
			System.out.println("ah");
			newlstUsersModel.addElement(p);
		}
		DefaultListModel newlstFilesModel = new DefaultListModel();
		for (FileDetails fd : GUI1.myProject.fileToPeerMap.keySet()) {
			System.out.println("ahhh");
			newlstFilesModel.addElement(fd);
		}

		lstUsers.setModel(newlstUsersModel);
		lstFiles.setModel(newlstFilesModel);

		repaint();
		validate();
	}

	private void lstUsersValueChanged(ListSelectionEvent e)
	{
		if (!e.getValueIsAdjusting() && e.getSource() != lstFiles) {
			if (lstUsers.getSelectedValue() != null) {
			lastSelectedPeer = (Peer) lstUsers.getSelectedValue();
			}

			//		DefaultListModel newlstUsersModel = new DefaultListModel();
			//		for (Object o : GUI1.myProject.peerToFileMap.keySet())
			//		{
			//			newlstUsersModel.addElement(o);
			//		}

			/*if (lstUsers.getSelectedIndex() == -1)
		{
			return;
		}*/
			


			DefaultListModel newlstFilesModel = new DefaultListModel();

			for (Object o : GUI1.myProject.peerToFileMap.get(lstUsers.getSelectedValue()))
			{
				newlstFilesModel.addElement(o);
			}
			
			ListSelectionListener old = lstFiles.getListSelectionListeners()[0];
			lstFiles.removeListSelectionListener(lstFiles.getListSelectionListeners()[0]);
			lstFiles.setModel(newlstFilesModel);
			if (lastSelectedFile != null && lstFiles != null) {
				lstFiles.setSelectedValue(lastSelectedFile, true);
			}
			lstFiles.addListSelectionListener(old);
			
//			lstFiles = new JList();
//			lstFiles.setModel(newlstFilesModel);

//			lstFiles.addListSelectionListener(new ListSelectionListener()
//			{
//				@Override
//				public void valueChanged(ListSelectionEvent e)
//				{
//					lstFilesValueChanged(e);
//				}
//			});
//			//lstFiles.removeListSelectionListener(listener)
//			//lstFiles.setModel(newlstFilesModel);
//			//		lstUsers.setModel(newlstUsersModel);

			repaint();
			validate();
		}
	}

	private void showAllButtonActionPerformed(ActionEvent e)
	{
		DefaultListModel newlstFilesModel = new DefaultListModel();
		DefaultListModel newlstUsersModel = new DefaultListModel();
		for (Object o : GUI1.myProject.peerToFileMap.keySet())
		{
			newlstUsersModel.addElement(o);
		}

		for (Object o : GUI1.myProject.fileToPeerMap.keySet())
		{
			newlstFilesModel.addElement(o);
		}
		lstFiles.setSelectedIndex(-1);
		lstUsers.setSelectedIndex(-1);
		lstUsers.setModel(newlstUsersModel);
		lstFiles.setModel(newlstFilesModel);

	}

	private void lstFilesValueChanged(ListSelectionEvent e)
	{
		if (!e.getValueIsAdjusting() && e.getSource() != lstUsers) {
		if (lstFiles.getSelectedValue() != null) {
			lastSelectedFile = (FileDetails) lstFiles.getSelectedValue();
		}

//		DefaultListModel newlstFilesModel = new DefaultListModel();
//		for (Object o : GUI1.myProject.fileToPeerMap.keySet())
//		{
//			newlstFilesModel.addElement(o);
//		}
//
//		if (lstFiles.getSelectedIndex() == -1)
//		{
//			return;
//		}
		


		DefaultListModel newlstUsersModel = new DefaultListModel();

		for (Object o : GUI1.myProject.fileToPeerMap.get(lstFiles.getSelectedValue()))
		{
			newlstUsersModel.addElement(o);
		}
		

		
		ListSelectionListener old = lstUsers.getListSelectionListeners()[0];
		lstUsers.removeListSelectionListener(lstUsers.getListSelectionListeners()[0]);
		lstUsers.setModel(newlstUsersModel);
		if (lastSelectedPeer != null && lstUsers != null) {
			lstUsers.setSelectedValue(lastSelectedPeer, true);
		}
		lstUsers.addListSelectionListener(old);
//		lstFiles.setModel(newlstFilesModel);
		//lstUsers.setModel(newlstUsersModel);
//		lstUsers = new JList();
//		lstUsers.setModel(newlstUsersModel);

//		lstUsers.addListSelectionListener(new ListSelectionListener()
//		{
//			@Override
//			public void valueChanged(ListSelectionEvent e)
//			{
//				lstUsersValueChanged(e);
//			}
//		});
		repaint();
		validate();
		}

	}

	private void changeDirectoryButtonActionPerformed(ActionEvent e)
	{
		fileChooser.showDialog(this, "Select");
		downloadDirectory = fileChooser.getSelectedFile();
	}

	private void initComponents()
	{

		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - william malick
		menuBar1 = new JMenuBar();
		menu1 = new JMenu();
		settingsMenu = new JMenuItem();
		helpMenu = new JMenuItem();
		menuItem1 = new JMenuItem();
		redPanel = new JPanel();
		label4 = new JLabel();
		scrollPane4 = new JScrollPane();
		lstDownloads = new JList();
		usersPanel = new JPanel();
		scrollPane2 = new JScrollPane();
		lstUsers = new JList();
		label2 = new JLabel();
		searchUsersField = new JTextField();
		filesPanel = new JPanel();
		scrollPane1 = new JScrollPane();
		lstFiles = new JList();
		label1 = new JLabel();
		searchFilesField = new JTextField();
		bluePanel = new JPanel();
		lblFileName = new JLabel();
		lblDateModified = new JLabel();
		lblFileSize = new JLabel();
		lblHashCode = new JLabel();
		fastestButton = new JButton();
		lastModifiedButton = new JButton();
		scrollPane3 = new JScrollPane();
		lslPeopleWhoHaveThis = new JList();
		label3 = new JLabel();
		downloadButton = new JButton();
		connectField = new JTextField();
		label6 = new JLabel();
		connectButton = new JButton();
		refreshButton = new JButton();
		showAllButton = new JButton();
		settingsDialog = new JDialog();
		settingsPanel = new JPanel();
		checkBox1 = new JCheckBox();
		checkBox2 = new JCheckBox();
		toggleButton1 = new JToggleButton();
		label5 = new JLabel();
		portField = new JTextField();
		okButton = new JButton();
		changeDirectoryButton = new JButton();
		fileChooser = new JFileChooser();

		// ======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(null);

		// ======== menuBar1 ========
		{

			// ======== menu1 ========
			{
				menu1.setText("File");

				// ---- settingsMenu ----
				settingsMenu.setText("Settings");
				settingsMenu.addActionListener(new ActionListener()
				{
					@Override
					public void actionPerformed(ActionEvent e)
					{
						settingsMenuActionPerformed(e);
					}
				});
				menu1.add(settingsMenu);

				// ---- helpMenu ----
				helpMenu.setText("Help");
				helpMenu.addActionListener(new ActionListener()
				{
					@Override
					public void actionPerformed(ActionEvent e)
					{
						menuItem2ActionPerformed(e);
					}
				});
				menu1.add(helpMenu);

				// ---- menuItem1 ----
				menuItem1.setText("Exit!");
				menu1.add(menuItem1);
			}
			menuBar1.add(menu1);
		}
		setJMenuBar(menuBar1);

		// ======== redPanel ========
		{
			redPanel.setBackground(new Color(144, 31, 0));

			// JFormDesigner evaluation mark
			redPanel.setBorder(new javax.swing.border.CompoundBorder(new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0), "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.red), redPanel.getBorder()));
			redPanel.addPropertyChangeListener(new java.beans.PropertyChangeListener()
			{
				public void propertyChange(java.beans.PropertyChangeEvent e)
				{
					if ("border".equals(e.getPropertyName()))
						throw new RuntimeException();
				}
			});

			redPanel.setLayout(null);

			// ---- label4 ----
			label4.setText("Downloads");
			label4.setForeground(Color.white);
			label4.setFont(new Font("Dialog", Font.PLAIN, 20));
			redPanel.add(label4);
			label4.setBounds(new Rectangle(new Point(90, 5), label4.getPreferredSize()));

			// ======== scrollPane4 ========
			{

				// ---- lstDownloads ----
				lstDownloads.setModel(new AbstractListModel()
				{
					String[] values = {  };

					public int getSize()
					{
						return values.length;
					}

					public Object getElementAt(int i)
					{
						return values[i];
					}
				});
				scrollPane4.setViewportView(lstDownloads);
			}
			redPanel.add(scrollPane4);
			scrollPane4.setBounds(15, 35, 265, 240);
		}
		contentPane.add(redPanel);
		redPanel.setBounds(370, 530, 295, 285);

		// ======== usersPanel ========
		{
			usersPanel.setBorder(new TitledBorder(null, "Users", TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION));
			usersPanel.setLayout(null);

			// ======== scrollPane2 ========
			{

				// ---- lstUsers ----
				lstUsers.setModel(new AbstractListModel()
				{
					String[] values = { };

					public int getSize()
					{
						return values.length;
					}

					public Object getElementAt(int i)
					{
						return values[i];
					}
				});
				lstUsers.addListSelectionListener(new ListSelectionListener()
				{
					@Override
					public void valueChanged(ListSelectionEvent e)
					{
						lstUsersValueChanged(e);
					}
				});
				scrollPane2.setViewportView(lstUsers);
			}
			usersPanel.add(scrollPane2);
			scrollPane2.setBounds(10, 40, 290, 445);

			// ---- label2 ----
			label2.setText("Search:");
			usersPanel.add(label2);
			label2.setBounds(new Rectangle(new Point(60, 10), label2.getPreferredSize()));
			usersPanel.add(searchUsersField);
			searchUsersField.setBounds(110, 10, 165, searchUsersField.getPreferredSize().height);

			{ // compute preferred size
				Dimension preferredSize = new Dimension();
				for (int i = 0; i < usersPanel.getComponentCount(); i++)
				{
					Rectangle bounds = usersPanel.getComponent(i).getBounds();
					preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
					preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
				}
				Insets insets = usersPanel.getInsets();
				preferredSize.width += insets.right;
				preferredSize.height += insets.bottom;
				usersPanel.setMinimumSize(preferredSize);
				usersPanel.setPreferredSize(preferredSize);
			}
		}
		contentPane.add(usersPanel);
		usersPanel.setBounds(355, 40, 305, 485);

		// ======== filesPanel ========
		{
			filesPanel.setBorder(new TitledBorder("Files"));
			filesPanel.setLayout(null);

			// ======== scrollPane1 ========
			{

				// ---- lstFiles ----
				lstFiles.setModel(new AbstractListModel()
				{
					String[] values = {  };

					public int getSize()
					{
						return values.length;
					}

					public Object getElementAt(int i)
					{
						return values[i];
					}
				});
				lstFiles.addListSelectionListener(new ListSelectionListener()
				{
					@Override
					public void valueChanged(ListSelectionEvent e)
					{
						lstFilesValueChanged(e);
					}
				});
				scrollPane1.setViewportView(lstFiles);
			}
			filesPanel.add(scrollPane1);
			scrollPane1.setBounds(10, 40, 325, 445);

			// ---- label1 ----
			label1.setText("Search:");
			filesPanel.add(label1);
			label1.setBounds(new Rectangle(new Point(45, 10), label1.getPreferredSize()));
			filesPanel.add(searchFilesField);
			searchFilesField.setBounds(95, 10, 165, searchFilesField.getPreferredSize().height);

			{ // compute preferred size
				Dimension preferredSize = new Dimension();
				for (int i = 0; i < filesPanel.getComponentCount(); i++)
				{
					Rectangle bounds = filesPanel.getComponent(i).getBounds();
					preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
					preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
				}
				Insets insets = filesPanel.getInsets();
				preferredSize.width += insets.right;
				preferredSize.height += insets.bottom;
				filesPanel.setMinimumSize(preferredSize);
				filesPanel.setPreferredSize(preferredSize);
			}
		}
		contentPane.add(filesPanel);
		filesPanel.setBounds(10, 35, 340, 490);

		// ======== bluePanel ========
		{
			bluePanel.setBackground(new Color(204, 255, 255));
			bluePanel.setLayout(null);

			// ---- lblFileName ----
			lblFileName.setText("File Name");
			bluePanel.add(lblFileName);
			lblFileName.setBounds(5, 15, 155, lblFileName.getPreferredSize().height);

			// ---- lblDateModified ----
			lblDateModified.setText("Date Modified");
			bluePanel.add(lblDateModified);
			lblDateModified.setBounds(5, 45, 145, lblDateModified.getPreferredSize().height);

			// ---- lblFileSize ----
			lblFileSize.setText("File Size");
			bluePanel.add(lblFileSize);
			lblFileSize.setBounds(5, 75, 145, lblFileSize.getPreferredSize().height);

			// ---- lblHashCode ----
			lblHashCode.setText("Hash Code");
			bluePanel.add(lblHashCode);
			lblHashCode.setBounds(5, 105, 145, lblHashCode.getPreferredSize().height);

			// ---- fastestButton ----
			fastestButton.setText("Fastest");
			fastestButton.addActionListener(new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent e)
				{
					fastestButtonActionPerformed(e);
					fastestButtonActionPerformed(e);
				}
			});
			bluePanel.add(fastestButton);
			fastestButton.setBounds(new Rectangle(new Point(30, 205), fastestButton.getPreferredSize()));

			// ---- lastModifiedButton ----
			lastModifiedButton.setText("Last Modified");
			lastModifiedButton.addActionListener(new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent e)
				{
					lastModifiedButtonActionPerformed(e);
				}
			});
			bluePanel.add(lastModifiedButton);
			lastModifiedButton.setBounds(new Rectangle(new Point(15, 230), lastModifiedButton.getPreferredSize()));

			// ======== scrollPane3 ========
			{

				// ---- lslPeopleWhoHaveThis ----
				lslPeopleWhoHaveThis.setModel(new AbstractListModel()
				{
					String[] values = { };

					public int getSize()
					{
						return values.length;
					}

					public Object getElementAt(int i)
					{
						return values[i];
					}
				});
				scrollPane3.setViewportView(lslPeopleWhoHaveThis);
			}
			bluePanel.add(scrollPane3);
			scrollPane3.setBounds(150, 25, 190, 245);

			// ---- label3 ----
			label3.setText("People who have this");
			bluePanel.add(label3);
			label3.setBounds(new Rectangle(new Point(175, 5), label3.getPreferredSize()));

			// ---- downloadButton ----
			downloadButton.setText("DOWNLOAD");
			downloadButton.setFont(new Font("DialogInput", Font.BOLD, 20));
			downloadButton.addActionListener(new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent e)
				{
					downloadButtonActionPerformed(e);
					downloadButtonActionPerformed(e);
				}
			});
			bluePanel.add(downloadButton);
			downloadButton.setBounds(new Rectangle(new Point(5, 170), downloadButton.getPreferredSize()));
		}
		contentPane.add(bluePanel);
		bluePanel.setBounds(15, 530, 345, 285);
		contentPane.add(connectField);
		connectField.setBounds(280, 10, 145, connectField.getPreferredSize().height);

		// ---- label6 ----
		label6.setText("IP Address:");
		contentPane.add(label6);
		label6.setBounds(new Rectangle(new Point(200, 10), label6.getPreferredSize()));

		// ---- connectButton ----
		connectButton.setText("Connect");
		connectButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				connectButtonActionPerformed(e);
			}
		});
		contentPane.add(connectButton);
		connectButton.setBounds(new Rectangle(new Point(430, 10), connectButton.getPreferredSize()));

		// ---- refreshButton ----
		refreshButton.setText("Refresh");
		refreshButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e) {
				refreshButtonActionPerformed(e);
			}
		});
		contentPane.add(refreshButton);
		refreshButton.setBounds(new Rectangle(new Point(95, 10), refreshButton.getPreferredSize()));

		// ---- showAllButton ----
		showAllButton.setText("Show All");
		showAllButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				showAllButtonActionPerformed(e);
			}
		});
		contentPane.add(showAllButton);
		showAllButton.setBounds(new Rectangle(new Point(530, 10), showAllButton.getPreferredSize()));

		contentPane.setPreferredSize(new Dimension(690, 870));
		pack();
		setLocationRelativeTo(getOwner());

		// ======== settingsDialog ========
		{
			settingsDialog.setModal(true);
			settingsDialog.setTitle("Settings");
			Container settingsDialogContentPane = settingsDialog.getContentPane();
			settingsDialogContentPane.setLayout(null);

			// ======== settingsPanel ========
			{

				// JFormDesigner evaluation mark
				settingsPanel.setBorder(new javax.swing.border.CompoundBorder(new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0), "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.red), settingsPanel.getBorder()));
				settingsPanel.addPropertyChangeListener(new java.beans.PropertyChangeListener()
				{
					public void propertyChange(java.beans.PropertyChangeEvent e)
					{
						if ("border".equals(e.getPropertyName()))
							throw new RuntimeException();
					}
				});

				settingsPanel.setLayout(null);

				// ---- checkBox1 ----
				checkBox1.setText("Use this");
				settingsPanel.add(checkBox1);
				checkBox1.setBounds(new Rectangle(new Point(55, 40), checkBox1.getPreferredSize()));

				// ---- checkBox2 ----
				checkBox2.setText("No, use this");
				settingsPanel.add(checkBox2);
				checkBox2.setBounds(new Rectangle(new Point(60, 75), checkBox2.getPreferredSize()));

				// ---- toggleButton1 ----
				toggleButton1.setText("Don't use this");
				settingsPanel.add(toggleButton1);
				toggleButton1.setBounds(new Rectangle(new Point(65, 110), toggleButton1.getPreferredSize()));

				// ---- label5 ----
				label5.setText("PORT:");
				settingsPanel.add(label5);
				label5.setBounds(new Rectangle(new Point(45, 145), label5.getPreferredSize()));

				// ---- portField ----
				portField.setText("8888");
				settingsPanel.add(portField);
				portField.setBounds(85, 145, 65, portField.getPreferredSize().height);

				// ---- okButton ----
				okButton.setText("OK");
				okButton.addActionListener(new ActionListener()
				{
					@Override
					public void actionPerformed(ActionEvent e)
					{
						okButtonActionPerformed(e);
					}
				});
				settingsPanel.add(okButton);
				okButton.setBounds(80, 245, 65, okButton.getPreferredSize().height);

				// ---- changeDirectoryButton ----
				changeDirectoryButton.setText("Change Download Directory");
				changeDirectoryButton.addActionListener(new ActionListener()
				{
					@Override
					public void actionPerformed(ActionEvent e)
					{
						changeDirectoryButtonActionPerformed(e);
					}
				});
				settingsPanel.add(changeDirectoryButton);
				changeDirectoryButton.setBounds(30, 300, 195, changeDirectoryButton.getPreferredSize().height);

				{ // compute preferred size
					Dimension preferredSize = new Dimension();
					for (int i = 0; i < settingsPanel.getComponentCount(); i++)
					{
						Rectangle bounds = settingsPanel.getComponent(i).getBounds();
						preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
						preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
					}
					Insets insets = settingsPanel.getInsets();
					preferredSize.width += insets.right;
					preferredSize.height += insets.bottom;
					settingsPanel.setMinimumSize(preferredSize);
					settingsPanel.setPreferredSize(preferredSize);
				}
			}
			settingsDialogContentPane.add(settingsPanel);
			settingsPanel.setBounds(0, 5, 235, 340);

			{ // compute preferred size
				Dimension preferredSize = new Dimension();
				for (int i = 0; i < settingsDialogContentPane.getComponentCount(); i++)
				{
					Rectangle bounds = settingsDialogContentPane.getComponent(i).getBounds();
					preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
					preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
				}
				Insets insets = settingsDialogContentPane.getInsets();
				preferredSize.width += insets.right;
				preferredSize.height += insets.bottom;
				settingsDialogContentPane.setMinimumSize(preferredSize);
				settingsDialogContentPane.setPreferredSize(preferredSize);
			}
			settingsDialog.pack();
			settingsDialog.setLocationRelativeTo(settingsDialog.getOwner());
		}
		// //GEN-END:initComponents

		//myProject = new ProjectManager(8888);
		//peers = myProject.activeConnections;
		//peerToFileMap = myProject.peerToFileMap;
		//fileToPeerMap = myProject.fileToPeerMap;
		/*ArrayList<Peer> shit = new ArrayList();
		try
		{
			shit.add(new Peer(0, InetAddress.getByAddress(new byte[] { 1, 1, 1, 1 }), "Erik", 8888, 0));
			shit.add(new Peer(0, InetAddress.getByAddress(new byte[] { 2, 2, 2, 2 }), "Michael", 8888, 0));
			shit.add(new Peer(0, InetAddress.getByAddress(new byte[] { 3, 3, 3, 3 }), "John", 8888, 0));
			shit.add(new Peer(0, InetAddress.getByAddress(new byte[] { 4, 4, 4, 4 }), "Jeannette", 8888, 0));
		} catch (Exception ex)
		{
			System.out.println("Sime");
		}
		ArrayList<FileDetails> a = new ArrayList(); // Erik's Files
		ArrayList<FileDetails> b = new ArrayList(); // My Files
		ArrayList<FileDetails> c = new ArrayList(); // John's
		ArrayList<FileDetails> d = new ArrayList(); // Jeannette's
		a.add(new FileDetails("Erik's File", 55, 10, 0, shit.get(0).ipAddress));
		a.add(new FileDetails("Erik's Other File", 16, 10, 0, shit.get(0).ipAddress));
		b.add(new FileDetails("Michael's File", 117, 10, 0, shit.get(1).ipAddress));
		c.add(new FileDetails("John's File", 4000, 10, 0, shit.get(2).ipAddress));
		d.add(new FileDetails("The Internet", 1, 10, 0, shit.get(3).ipAddress));

		peerToFileMap.put(shit.get(0), a);
		peerToFileMap.put(shit.get(1), b);
		peerToFileMap.put(shit.get(2), c);
		peerToFileMap.put(shit.get(3), d);*/

		/*allPeers = new HashSet<Peer>();

		DefaultListModel gumbo = new DefaultListModel();
		DefaultListModel rue = new DefaultListModel();
		for (Peer p : shit)
		{
			gumbo.addElement(p);
			ArrayList<FileDetails> tempList = peerToFileMap.get(p);

			for (FileDetails f : tempList)
			{
				ArrayList<Peer> bullshit = new ArrayList<Peer>();
				bullshit.add(p);
				fileToPeerMap.put(f, bullshit);
				System.out.println(fileToPeerMap.get(f) + "is he missing something?");
				rue.addElement(f);

			}

		}*/

		/*lstUsers.setModel(gumbo);

		allPeers.addAll(shit);
		allFiles = fileToPeerMap.keySet();

		lstFiles.setModel(rue);*/

	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - william malick
	private JMenuBar menuBar1;
	private JMenu menu1;
	private JMenuItem settingsMenu;
	private JMenuItem helpMenu;
	private JMenuItem menuItem1;
	private JPanel redPanel;
	private JLabel label4;
	private JScrollPane scrollPane4;
	private JList lstDownloads;
	private JPanel usersPanel;
	private JScrollPane scrollPane2;
	private JList lstUsers;
	private JLabel label2;
	private JTextField searchUsersField;
	private JPanel filesPanel;
	private JScrollPane scrollPane1;
	private JList lstFiles;
	private JLabel label1;
	private JTextField searchFilesField;
	private JPanel bluePanel;
	private JLabel lblFileName;
	private JLabel lblDateModified;
	private JLabel lblFileSize;
	private JLabel lblHashCode;
	private JButton fastestButton;
	private JButton lastModifiedButton;
	private JScrollPane scrollPane3;
	private JList lslPeopleWhoHaveThis;
	private JLabel label3;
	private JButton downloadButton;
	private JTextField connectField;
	private JLabel label6;
	private JButton connectButton;
	private JButton refreshButton;
	private JButton showAllButton;
	private JDialog settingsDialog;
	private JPanel settingsPanel;
	private JCheckBox checkBox1;
	private JCheckBox checkBox2;
	private JToggleButton toggleButton1;
	private JLabel label5;
	private JTextField portField;
	private JButton okButton;
	private JButton changeDirectoryButton;
	private JFileChooser fileChooser;
	// JFormDesigner - End of variables declaration //GEN-END:variables

	public static void main(String[] args) {
		GUI1 g = new GUI1();
		g.setVisible(true);
	}
}
